package tutorial.java.dragdrop;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

public class ComboboxDemo extends JFrame {

	private JPanel contentPane;
	private JComboBox comboBox_Name;
	private DefaultComboBoxModel model;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ComboboxDemo frame = new ComboboxDemo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ComboboxDemo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		comboBox_Name = new JComboBox();
		comboBox_Name.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					JOptionPane.showMessageDialog(null, "Changed");
				}
			}
		});
		comboBox_Name.setBounds(151, 33, 85, 20);
		contentPane.add(comboBox_Name);
		
		init();
	}

	public void init() {
		// TODO Auto-generated method stub
		model = new DefaultComboBoxModel();
		model.addElement("Hai");
		model.addElement("Oanh");
		model.addElement("Sơn");
		model.addElement("Nga");
		
		comboBox_Name.setModel(model);
	}
}
